package com.wm.web.action;

import java.util.Date;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;

import com.wm.bean.Restaurant;
import com.wm.bean.Shopkeeper;
import com.wm.bean.User;
import com.wm.comm.Constant;
import com.wm.comm.MD5;
import com.wm.comm.PinYinUtil;
import com.wm.service.RestaurantService;
import com.wm.service.ShopkeeperService;
import com.wm.service.UserService;
import com.wm.web.interceptor.RemoteAddrAware;
import com.wm.web.interceptor.ShopkeeperSessionAware;
import com.wm.web.servlet.*;

public class ShopkeeperRestaurant extends BaseAction implements SessionAware,ShopkeeperSessionAware{
	private static final Log logger = LogFactory.getLog(ShopkeeperRestaurant.class);
	
	private ShopkeeperService shopkeeperService;
	private RestaurantService restaurantService;

	public ShopkeeperService getShopkeeperService() {
		return shopkeeperService;
	}

	public void setShopkeeperService(ShopkeeperService shopkeeperService) {
		this.shopkeeperService = shopkeeperService;
	}
	
	public RestaurantService getRestaurantService() {
		return restaurantService;
	}

	public void setRestaurantService(RestaurantService restaurantService) {
		this.restaurantService = restaurantService;
	}
	
	private ShopkeeperSession shopkeeperSession;
	private Map session;
	
	public ShopkeeperSession getShopkeeperSession() {
		return shopkeeperSession;
	}

	public void setShopkeeperSession(ShopkeeperSession shopkeeperSession) {
		this.shopkeeperSession = shopkeeperSession;
	}

	public Map getSession() {
		return session;
	}
	
	public void setSession(Map session) {
		this.session = session;
	}	
	
	private String phone;				//联系电话
	private String phone2;				//联系电话2
	private String resName = "";		//饭店名称
	private String address;				//地址
	private String summary;				//饭店简介
	private String notice;				//饭店公告
	private String shopkeeperName;		//店主姓名
	private String qq;					//QQ
	private String webKey;				//网站key
	
	private String error;
	
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getPhone2() {
		return phone2;
	}

	public void setPhone2(String phone2) {
		this.phone2 = phone2;
	}

	public String getResName() {
		return resName;
	}

	public void setResName(String resName) {
		this.resName = resName;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	public String getNotice() {
		return notice;
	}

	public void setNotice(String notice) {
		this.notice = notice;
	}
	
	public String getShopkeeperName() {
		return shopkeeperName;
	}

	public void setShopkeeperName(String shopkeeperName) {
		this.shopkeeperName = shopkeeperName;
	}

	public String getQq() {
		return qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	public String getWebKey() {
		return webKey;
	}

	public void setWebKey(String webKey) {
		this.webKey = webKey;
	}

	public String getError() {
		return error;
	}

	public void setError(String error) {
		this.error = error;
	}
	public String execute() {
		try {
			return this.executeMethod(this.getAction());
		} catch (Exception e) {
			logger.error(e);
			return INPUT;
		}
	}

	/**
	 * 初始页
	 */
	public String index(){
		this.setAction("save");
		Restaurant restaurant = this.getRestaurantService().findRestaurantById(shopkeeperSession.getSkid());
		this.setResName(restaurant.getResName());
		this.setSummary(restaurant.getSummary());
		this.setAddress(restaurant.getAddress());
		this.setNotice(restaurant.getNotice());
		this.setPhone(restaurant.getPhone());
		this.setPhone2(restaurant.getPhone2());
		this.setShopkeeperName(restaurant.getShopkeeperName());
		this.setQq(restaurant.getQq());
		this.setWebKey(restaurant.getWebKey());
		return "index";
	}
	
	/**
	 * 更新
	 */
	public String save(){
		Restaurant restaurant = this.getRestaurantService().findRestaurantById(shopkeeperSession.getSkid());
		restaurant.setResName(this.resName);
		restaurant.setSummary(this.summary);
		restaurant.setAddress(this.address);
		restaurant.setNotice(this.notice);
		restaurant.setPhone(this.phone);
		restaurant.setPhone2(this.phone2);
		restaurant.setShopkeeperName(this.shopkeeperName);
		restaurant.setQq(this.qq);
		restaurant.setWebKey(this.webKey);
		try {
			this.getRestaurantService().updateRestaurant(restaurant);
		} catch (Exception e) {
			this.addActionError(this.getText("error.saveerror"));
			return ERROR;
		}
		this.addFieldError("error", this.getText("error.save"));
		this.setError("1");
		return "index";
	} 

}
